package com.szosen.idcardActivity;

import java.util.List;

import utils.ICCardUtils;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Matrix;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import bean.SSCardBean;

import com.decard.NDKMethod.BasicOper;
import com.decard.entitys.IDCard;
import com.grg.idcard.IDCardMsg;
import com.grg.idcard.IDCardRecognition;
import com.grg.idcard.IDCardRecognition.IDCardRecListener;
import com.szosen.bluetooth.BluetoothListActivity;
import com.szosen.database.DBService;
import com.szosen.database.HealthRecord;
import com.szosen.jkzj.R;
import com.szosen.jkzj.activity.BaseActivity;
import com.szosen.jkzj.activity.JKDAActivity;
import com.szosen.jkzj.util.Contants;
import com.szosen.json.database.ArchiveBean;
import com.szosen.json.database.JSONDBService;
import com.szosen.util.StringUtils;
import com.szosen.util.ToastTool;
import com.szosen.util.Tools;

/***
 * 这是外置的社保卡，20170527
 */
@SuppressLint("NewApi")
public class IDCardActivity_SB_waizhi extends BaseActivity {

	Dialog dialog;
	private Context mContext;
	private TextView tv_putIdCard;
	private String uid2;

	/** Called when the activity is first created. */

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.read_id_card_new);
		mContext = this;
		btconn = (Button) findViewById(R.id.btn_find_id_reader);
		btread = (Button) findViewById(R.id.btnInit);
		btclose = (Button) findViewById(R.id.btn_off);
		image = (ImageView) findViewById(R.id.ivImageview);
		txtInfo = (TextView) findViewById(R.id.tv_info);
		txtDeviceStatus = (TextView) findViewById(R.id.conn_status);
		tv_putIdCard = (TextView) findViewById(R.id.readidcard_tv_putidcard);
		tv_putIdCard.setText("请放入社保卡");
		tv_putIdCard.setVisibility(View.VISIBLE);
		// TextView tv_title = (TextView) findViewById(R.id.main_all_tv_title);
		// tv_title.setText("身份证读卡");
		// btclose.setEnabled(false);
		txtInfo.setText("你好");
		image.setVisibility(View.INVISIBLE);
		txtInfo.setVisibility(View.INVISIBLE);
		txtDeviceStatus.setVisibility(View.INVISIBLE);
		txtDeviceStatus
				.setText(Contants.Bluetooth_connecting.BLUETOOTH_CONNECTING);
		txtDeviceStatus.setTextColor(Color.BLUE);
		btread.setOnClickListener(new Button.OnClickListener() {
			public void onClick(View v) {
				image.setVisibility(View.INVISIBLE);
				txtInfo.setVisibility(View.INVISIBLE);
				tv_putIdCard.setVisibility(View.VISIBLE);// 只显示放进身份证。。。
			}
		});
	}

	public void connnectDeviceAgain(View view) {
		startReadIdCard();
	}

	private int reqPermission2 = 0;
	BasicOper oper2;

	private void startReadIdCard() {
		this.oper2 = new BasicOper();
		BasicOper paramBundle = this.oper2;
		this.reqPermission2 = BasicOper.dc_AUSB_ReqPermission(this);
		if (this.reqPermission2 == -1) {
			Toast.makeText(this, "USB初始化错误！", 0).show();
		}
		new Thread(new ThreadRuns(null)).start();
		if (this.reqPermission2 == -1) {
			Toast.makeText(this, "未寻找到符合指定VID,PID的设备！", 0).show();
		} else {
			if (BasicOper.dc_open("AUSB", this, null, 0) > 0) {
				Toast.makeText(this, "打开设备成功！", 0).show();
			} else {
				Toast.makeText(this, "打开设备失败！", 0).show();
			}
		}
	}

	private boolean isRun2 = true;

	private class ThreadRuns implements Runnable {

		private ThreadRuns(Object object) {
		}

		public void run() {
			while (IDCardActivity_SB_waizhi.this.isRun2) {
				try {
					IDCardActivity_SB_waizhi.this.ReadCard();
					Thread.sleep(300L);
					IDCardActivity_SB_waizhi.this.ReadCpu();
					Thread.sleep(300L);
					// IDCardActivity_SB_waizhi.this.handler.sendEmptyMessage(1);
					// IDCardActivity_SB_waizhi.this.handler.sendEmptyMessage(0);
					Thread.sleep(800L);
					if (BasicOper.dc_card_exist().equals("0000|1008")) {
						IDCardActivity_SB_waizhi.this.ReadCard();
					}
				} catch (InterruptedException localInterruptedException) {
					if (BasicOper.dc_card_exist().equals("0000|1004")) {
						IDCardActivity_SB_waizhi.this.ReadCpu();
					} else if (BasicOper.dc_card_exist().equals("0000|100C")) {
						IDCardActivity_SB_waizhi.this.handler
								.sendEmptyMessage(-2);
					} else {
						IDCardActivity_SB_waizhi.this.handler
								.sendEmptyMessage(-1);
					}
				}
			}
		}
	}

	private void ReadCpu() {
		BasicOper localBasicOper = this.oper2;
		this.m12 = BasicOper.dc_cpureset_hex();
		localBasicOper = this.oper2;
		this.m12 = BasicOper.dc_cpuapdu_hex("00A40000023F00");
		localBasicOper = this.oper2;
		this.m12 = BasicOper
				.dc_cpuapdu_hex("00A404000F7378312E73682EC9E7BBE1B1A3D5CF");
		localBasicOper = this.oper2;
		this.m12 = BasicOper.dc_cpuapdu_hex("00A4020002EF05");
		localBasicOper = this.oper2;
		this.distinguish2 = BasicOper.dc_cpuapdu_hex("00B2010012");
		localBasicOper = this.oper2;
		this.category2 = BasicOper.dc_cpuapdu_hex("00B2020003");
		localBasicOper = this.oper2;
		this.canonical2 = BasicOper.dc_cpuapdu_hex("00B2030006");
		localBasicOper = this.oper2;
		this.initialNumber2 = BasicOper.dc_cpuapdu_hex("00B204000E");
		localBasicOper = this.oper2;
		this.calidDate2 = BasicOper.dc_cpuapdu_hex("00B2050006");
		localBasicOper = this.oper2;
		this.expirationDate2 = BasicOper.dc_cpuapdu_hex("00B2060006");
		localBasicOper = this.oper2;
		this.cardNumber2 = BasicOper.dc_cpuapdu_hex("00B207000B");
		localBasicOper = this.oper2;
		this.m12 = BasicOper.dc_cpuapdu_hex("00A4020002EF06");
		localBasicOper = this.oper2;
		this.idNumber2 = BasicOper.dc_cpuapdu_hex("00B2080014");
		localBasicOper = this.oper2;
		this.name2 = BasicOper.dc_cpuapdu_hex("00B2090020");
		localBasicOper = this.oper2;
		this.sex2 = BasicOper.dc_cpuapdu_hex("00B20A0003");
		localBasicOper = this.oper2;
		this.nation2 = BasicOper.dc_cpuapdu_hex("00B20B0003");
		localBasicOper = this.oper2;
		this.address2 = BasicOper.dc_cpuapdu_hex("00B20C0005");
		localBasicOper = this.oper2;
		this.birthday2 = BasicOper.dc_cpuapdu_hex("00B20D0006");
		this.handler.sendEmptyMessage(1);

	}

	boolean isReadedOK = false;

	private IDCard idCard2;
	private Handler handler = new Handler() {
		public void handleMessage(Message paramAnonymousMessage) {
			super.handleMessage(paramAnonymousMessage);
			if (paramAnonymousMessage.what == 0) {
				// this.image2.setVisibility(0);
				// paramAnonymousMessage =
				// Analysis2.hex2Byte(this.idCard2.getPhotoDataHexStr());
				// paramAnonymousMessage =
				// this.Bytes2Bimap(paramAnonymousMessage);
				Log.i("bit", "handleMessage: " + paramAnonymousMessage);
				// this.image.setImageBitmap(paramAnonymousMessage);
				if (idCard2 == null) {
					return;
				}
				/*
				 * this.text2.setText("【身份证信息】\n姓名：" + this.idCard2.getName() +
				 * "\n性别：" + this.idCard2.getSex() + "\n出生日期：" +
				 * Analysis2.IdDate(this.idCard2 .getBirthday()) + "\n名族：" +
				 * this.idCard2.getNation() + "\n身份证号：" + this.idCard2.getId() +
				 * "\n签发机关：" + this.idCard2.getOffice() + "\n有效期限：" +
				 * Analysis2.IdDate(this.idCard2 .getStartTime()) + " —" +
				 * Analysis2.IdDate(this.idCard2 .getEndTime()) + "\n身份证UID：" +
				 * this.uid2);
				 */
				try {
					final String name = idCard2.getName();
					final String sex = idCard2.getSex();
					// final String birthday = idCard2.getBirthday();
					final String idCard = idCard2.getId();
					final String nation = idCard2.getNation();
					String birthday = Tools.getBirthdayByIdcard(idCard);
					String sb = "姓名：" + name + "\n" + "性别：" + sex + "\n"
							+ "民族：" + nation + "\n出生日期：" + birthday + "\n"
							+ "身份证号：" + idCard + "\n";
					if (TextUtils.isEmpty(idCard) || "解析失败".equals(idCard)
							|| isReadedOK) {
						return;
					}
					isReadedOK = true;
					image.setVisibility(View.INVISIBLE);
					txtInfo.setVisibility(View.VISIBLE);
					tv_putIdCard.setVisibility(View.INVISIBLE);
					txtInfo.setText(sb);
					boolean flag = false;
					JSONDBService dService = JSONDBService.getInstance(context);
					List<Object> list = dService.getAll(new ArchiveBean());
					for (int i = 0; list != null && i < list.size(); i++) {
						ArchiveBean hr = (ArchiveBean) list.get(i);
						String card = hr.getIdcard().trim();
						if (!TextUtils.isEmpty(card)
								&& card.equals(idCard.trim())) {
							Intent intent = new Intent();
							intent.putExtra("IdCard", idCard.trim());
							intent.putExtra("name", name.trim());
							setResult(0, intent);
							flag = true;
							finish();
						}
					}
					if (!flag) {
						Intent intent = new Intent(
								IDCardActivity_SB_waizhi.this,
								JKDAActivity.class);
						intent.putExtra("flag", "addUser");
						intent.putExtra("idCard", idCard);
						intent.putExtra("name", name);
						// intent.putExtra("address", info.getAddress());
						intent.putExtra("sex", sex);
						// intent.putExtra("nation", info.getNationStr());
						startActivity(intent);
						finish();
					}
					isRun2 = false;
				} catch (Exception e) {
					e.printStackTrace();
				}
			} else if (paramAnonymousMessage.what == 1) {
				/*
				 * this.image2.setVisibility(4); String sb = "【社保卡】\n卡片识别码：" +
				 * Analysis2.Distinguish(this.distinguish2) + "\n类别：" +
				 * Analysis2.Category(this.category2) + "\n规范版本：" +
				 * Analysis2.VersionNumber(this.canonical2, 17, 9) +
				 * "\n初始化机构编号：" + Analysis2 .InitialNumber(this.initialNumber2)
				 * + "\n发卡日期：" + Analysis2.Date(this.calidDate2) + "\n有效期：" +
				 * Analysis2.Date(this.expirationDate2); System.out.println(sb);
				 * String sb2 = "卡号：" + Analysis2.CardNumber(this.cardNumber2,
				 * 27, 9) + "\n社会保障号码/身份证号：" +
				 * Analysis2.IdNumber(this.idNumber2, 54, 17) + "\n姓名：" +
				 * Analysis2.decodeString(this.name2, "gb2312") + "\n性别：" +
				 * Analysis2.Sex(this.sex2) + "\n民族：" // +
				 * Analysis2.Nation(this.nation2) + "\n出生日期：" +
				 * Analysis2.Date(this.birthday2) + "\n";
				 * System.out.println(sb2);
				 */
				try {
					String name = Analysis2.decodeString(
							IDCardActivity_SB_waizhi.this.name2, "gb2312");
					String sex = Analysis2
							.Sex(IDCardActivity_SB_waizhi.this.sex2);
					String idCard = Analysis2.IdNumber(
							IDCardActivity_SB_waizhi.this.idNumber2, 54, 17);
					String nation = "";
					try {
						nation = Analysis2
								.Nation(IDCardActivity_SB_waizhi.this.nation2);
					} catch (Exception e) {
						e.printStackTrace();
						System.out.println("读取nation异常了");
					}
					if (TextUtils.isEmpty(idCard) || "解析失败".equals(idCard)
							|| isReadedOK) {
						return;
					}
					String birthday = Tools.getBirthdayByIdcard(idCard);
					String sb = "姓名：" + name + "\n" + "性别：" + sex + "\n"
							+ "民族：" + nation + "\n出生日期：" + birthday + "\n"
							+ "身份证号：" + idCard + "\n";
					image.setVisibility(View.INVISIBLE);
					txtInfo.setVisibility(View.VISIBLE);
					tv_putIdCard.setVisibility(View.INVISIBLE);
					txtInfo.setText(sb);
					boolean flag = false;
					JSONDBService dService = JSONDBService.getInstance(context);
					List<Object> list = dService.getAll(new ArchiveBean());
					for (int i = 0; list != null && i < list.size(); i++) {
						ArchiveBean hr = (ArchiveBean) list.get(i);
						String card = hr.getIdcard().trim();
						if (!TextUtils.isEmpty(card)
								&& card.equals(idCard.trim())) {
							Intent intent = new Intent();
							intent.putExtra("IdCard", idCard.trim());
							intent.putExtra("name", name.trim());
							setResult(0, intent);
							flag = true;
							finish();
						}
					}
					if (!flag) {
						Intent intent = new Intent(
								IDCardActivity_SB_waizhi.this,
								JKDAActivity.class);
						intent.putExtra("flag", "addUser");
						intent.putExtra("idCard", idCard);
						intent.putExtra("name", name);
						// intent.putExtra("address", info.getAddress());
						intent.putExtra("sex", sex);
						// intent.putExtra("nation", info.getNationStr());
						startActivity(intent);
						finish();
					}
					isReadedOK = true;
					isRun2 = false;
				} catch (Exception e) {
					e.printStackTrace();
				}
			} else if (paramAnonymousMessage.what == -1) {
			} else if (paramAnonymousMessage.what == -2) {
			}
		}
	};
	private String initialNumber2;
	private String accountAddressCode2;
	private String address2;
	private String birthday2;
	private Bitmap bitmap2;
	private String calidDate2;
	private String canonical2;
	private String cardNumber2;
	private String category2;
	private String distinguish2;
	private String expirationDate2;
	private String idNumber2;
	private int isData2 = -1;
	private String m12;
	private String m22;
	private String name2;
	private String nation2;
	private String permanentAddress2;
	private String postalAddress2;
	private String postcode2;
	private String registeredResidence2;
	private String residenceAddress2;
	private String residentAddressCode2;
	private String sex2;
	private String telephone2;
	private TextView text2;
	private TextView text022;
	private String unitMechanism2;
	private String unitName2;

	private void ReadCard() {
		BasicOper localBasicOper = this.oper2;
		this.idCard2 = BasicOper.dc_get_i_d_raw_info();
		localBasicOper = this.oper2;
		this.uid2 = BasicOper.dc_getuid_i_d().substring(5);
		if (this.idCard2 != null) {
			this.handler.sendEmptyMessage(0);
		}
	}

	private IDCardRecListener mIDCardRecListener = new IDCardRecListener() {
		@Override
		public void onResp(IDCardMsg info) {
			if (info == null) {
				// txtInfo.setText("");
				// image.setImageBitmap(null);
				return;
			}
			String text = info.getName() + "\n" + info.getSexStr() + "\n"
					+ info.getNationStr() + "族" + "\n" + info.getBirthDate()
					+ "\n" + info.getIdCardNum() + "\n" + info.getAddress()
					+ "\n" + "有效期：" + info.getUsefulStartDate() + "至"
					+ info.getUsefulEndDate() + "\n" + info.getSignOffice()
					+ "\n";
			// 读取到身份证图片
			image.setVisibility(View.VISIBLE);
			txtInfo.setVisibility(View.VISIBLE);
			tv_putIdCard.setVisibility(View.INVISIBLE);
			txtInfo.setText(text);
			Bitmap bitmap = BitmapFactory.decodeByteArray(info.getPortrait(),
					0, info.getPortrait().length);
			image.setImageBitmap(bitmap);
			List<Object> list = DBService.getInstance(context).getAll(
					new HealthRecord());
			boolean flag = false;
			for (int i = 0; i < list.size(); i++) {
				HealthRecord hr = (HealthRecord) list.get(i);
				String card = hr.getIdCard().trim();
				if (!TextUtils.isEmpty(card)) {
					Intent intent = new Intent();
					setResult(0, intent);
					flag = true;
					finish();
				}
			}
			if (!flag) {
				Intent intent = new Intent(IDCardActivity_SB_waizhi.this,
						JKDAActivity.class);
				intent.putExtra("flag", "addUser");
				intent.putExtra("idCard", info.getIdCardNum());
				intent.putExtra("name", info.getName());
				intent.putExtra("address", info.getAddress());
				intent.putExtra("sex", info.getSexStr());
				intent.putExtra("nation", info.getNationStr());
				startActivity(intent);
				finish();
			}

		}

		@Override
		public void onConnectState(String msg) {
			myReadIdCardHandler.obtainMessage(WHAT_CONNECTSUCCESS)
					.sendToTarget();
		}
	};

	@SuppressLint("ResourceAsColor")
	@Override
	protected void onResume() {
		super.onResume();
		super.setTitleContent("【身份证刷卡】");
		startReadIdCard();
	}

	@Override
	public void onBackPressed() {
		super.onBackPressed();
	}

	private Button btconn;
	private Button btread;
	private ImageView image;
	private Button btclose;
	private TextView txtDeviceStatus;// 读卡器连接状态
	private TextView txtInfo;

	private final static int WHAT_IMAGEVIEW = 111;
	private final static int WHAT_NAME = 222;
	private final static int WHAT_IMAGEDECODEFAILED = 444;
	private final static int WHAT_SHOWDIALOG = 666;
	private final static int WHAT_READIDCARDFAILED = 999;
	private final static int WHAT_READIDCARDERROR = 99999;
	private final static int WHAT_CONNECTERROR = 44444;
	private final static int WHAT_CONNECTSUCCESS = 66666;
	private final static int WHAT_CONNECTHAND = 55555;

	@SuppressWarnings("deprecation")
	@Override
	protected void onDestroy() {
		super.onDestroy();
		isRun2 = false;
//		oper2.dc_exit();
	}

	Handler myReadIdCardHandler = new Handler() {
		public void handleMessage(android.os.Message msg) {
			switch (msg.what) {
			case WHAT_IMAGEVIEW:
				// 读取到身份证图片
				image.setVisibility(View.VISIBLE);
				tv_putIdCard.setVisibility(View.INVISIBLE);
				Bitmap bmp = (Bitmap) msg.obj;
				image.setImageBitmap(bmp);
				break;
			case WHAT_NAME:
				// 读取到身份证名字
				// tv.setVisibility(View.VISIBLE);
				txtInfo.setVisibility(View.VISIBLE);
				tv_putIdCard.setVisibility(View.INVISIBLE);
				String s = (String) msg.obj;
				txtInfo.setText("您好, " + s);
				List<Object> list = DBService.getInstance(context).getAll(
						new HealthRecord());
				boolean flag = false;
				for (int i = 0; i < list.size(); i++) {
					HealthRecord hr = (HealthRecord) list.get(i);
					String card = hr.getIdCard().trim();
					if (!TextUtils.isEmpty(card)) {
						Intent intent = new Intent();
						System.out.println("进入到原来的列表");
						setResult(0, intent);
						flag = true;
						finish();
					}
				}
				if (!flag) {
					Intent intent = new Intent(IDCardActivity_SB_waizhi.this,
							JKDAActivity.class);
					// intent.putExtra("flag", "addUser");
					// intent.putExtra("idCard", mIdCardMsg.id_num);
					// intent.putExtra("name", mIdCardMsg.name);
					// intent.putExtra("address", mIdCardMsg.address);
					// intent.putExtra("sex", mIdCardMsg.sex);
					// intent.putExtra("nation", mIdCardMsg.nation_str);
					startActivity(intent);
					finish();
				}
				break;
			case WHAT_IMAGEDECODEFAILED:
				ToastTool.showShort(
						mContext,
						"照片解码失败，请检查路径"
								+ Environment.getExternalStorageDirectory()
								+ "/wltlib/");
				image.setImageBitmap(BitmapFactory.decodeResource(
						getResources(), R.drawable.face));
				image.setVisibility(View.INVISIBLE);
				// tv.setVisibility(View.INVISIBLE);
				break;
			case WHAT_CONNECTHAND:
				image.setVisibility(View.INVISIBLE);
				txtInfo.setVisibility(View.INVISIBLE);
				tv_putIdCard.setVisibility(View.INVISIBLE);
				break;
			case WHAT_SHOWDIALOG:
				// mReadIdCardFlag = false;
				tv_putIdCard.setVisibility(View.INVISIBLE);
				break;
			case WHAT_READIDCARDFAILED:
				tv_putIdCard.setVisibility(View.VISIBLE);
				break;
			case WHAT_READIDCARDERROR:
				// ToastTool.showShort(mContext, "");
				txtDeviceStatus
						.setText(Contants.Bluetooth_connecting.BLUETOOTH_CONNECT_NULL);
				txtDeviceStatus.setTextColor(Color.RED);
				break;
			case WHAT_CONNECTSUCCESS:
				tv_putIdCard.setVisibility(View.VISIBLE);// 设备连接成功后显示放进身份证。。。
				txtDeviceStatus
						.setText(Contants.Bluetooth_connecting.BLUETOOTH_CONNECTSUCCESS);
				txtDeviceStatus.setTextColor(Color.BLUE);
				break;
			case WHAT_CONNECTERROR:
				// ToastTool.showShort(mContext, "设备连接失败");
				txtDeviceStatus
						.setText(Contants.Bluetooth_connecting.BLUETOOTH_CONNECTFAILED);
				txtDeviceStatus.setTextColor(Color.RED);
				break;
			default:
				break;
			}
		};
	};

	private String decodeNation(int code) {
		String nation;
		switch (code) {
		case 1:
			nation = "汉";
			break;
		case 2:
			nation = "蒙古";
			break;
		case 3:
			nation = "回";
			break;
		case 4:
			nation = "藏";
			break;
		case 5:
			nation = "维吾尔";
			break;
		case 6:
			nation = "苗";
			break;
		case 7:
			nation = "彝";
			break;
		case 8:
			nation = "壮";
			break;
		case 9:
			nation = "布依";
			break;
		case 10:
			nation = "朝鲜";
			break;
		case 11:
			nation = "满";
			break;
		case 12:
			nation = "侗";
			break;
		case 13:
			nation = "瑶";
			break;
		case 14:
			nation = "白";
			break;
		case 15:
			nation = "土家";
			break;
		case 16:
			nation = "哈尼";
			break;
		case 17:
			nation = "哈萨克";
			break;
		case 18:
			nation = "傣";
			break;
		case 19:
			nation = "黎";
			break;
		case 20:
			nation = "傈僳";
			break;
		case 21:
			nation = "佤";
			break;
		case 22:
			nation = "畲";
			break;
		case 23:
			nation = "高山";
			break;
		case 24:
			nation = "拉祜";
			break;
		case 25:
			nation = "水";
			break;
		case 26:
			nation = "东乡";
			break;
		case 27:
			nation = "纳西";
			break;
		case 28:
			nation = "景颇";
			break;
		case 29:
			nation = "柯尔克孜";
			break;
		case 30:
			nation = "土";
			break;
		case 31:
			nation = "达斡尔";
			break;
		case 32:
			nation = "仫佬";
			break;
		case 33:
			nation = "羌";
			break;
		case 34:
			nation = "布朗";
			break;
		case 35:
			nation = "撒拉";
			break;
		case 36:
			nation = "毛南";
			break;
		case 37:
			nation = "仡佬";
			break;
		case 38:
			nation = "锡伯";
			break;
		case 39:
			nation = "阿昌";
			break;
		case 40:
			nation = "普米";
			break;
		case 41:
			nation = "塔吉克";
			break;
		case 42:
			nation = "怒";
			break;
		case 43:
			nation = "乌孜别克";
			break;
		case 44:
			nation = "俄罗斯";
			break;
		case 45:
			nation = "鄂温克";
			break;
		case 46:
			nation = "德昂";
			break;
		case 47:
			nation = "保安";
			break;
		case 48:
			nation = "裕固";
			break;
		case 49:
			nation = "京";
			break;
		case 50:
			nation = "塔塔尔";
			break;
		case 51:
			nation = "独龙";
			break;
		case 52:
			nation = "鄂伦春";
			break;
		case 53:
			nation = "赫哲";
			break;
		case 54:
			nation = "门巴";
			break;
		case 55:
			nation = "珞巴";
			break;
		case 56:
			nation = "基诺";
			break;
		case 97:
			nation = "其他";
			break;
		case 98:
			nation = "外国血统中国籍人士";
			break;
		default:
			nation = "";
			break;
		}
		return nation;
	}

	Bitmap bmp(Bitmap bp) {
		float scaleWidth = 1;
		float scaleHeight = 1;
		int bmpWidth = bp.getWidth();
		int bmpHeight = bp.getHeight();
		/* 设置图片放大的比例 */
		double scale = 2;
		/* 计算这次要放大的比例 */
		scaleWidth = (float) (scaleWidth * scale);
		scaleHeight = (float) (scaleHeight * scale);

		/* 产生reSize后的Bitmap对象 */
		Matrix matrix = new Matrix();
		matrix.postScale(scaleWidth, scaleHeight);
		Bitmap resizeBmp = Bitmap.createBitmap(bp, 0, 0, bmpWidth, bmpHeight,
				matrix, true);
		return resizeBmp;
	}
}